jQuery(document).ready(function($){
	var $timeline_block = $('.cd-timeline-block');

	//hide timeline blocks which are outside the viewport
	$timeline_block.each(function(){
		if($(this).offset().top > $(window).scrollTop()+$(window).height()) {
			$(this).find('.cd-timeline-img, .cd-timeline-content').addClass('is-hidden');
		}
	});

	//on scolling, show/animate timeline blocks when enter the viewport
	$(window).on('scroll', function(){
		$timeline_block.each(function(){
			if( $(this).offset().top <= $(window).scrollTop()+$(window).height()*0.75 && $(this).find('.cd-timeline-img').hasClass('is-hidden') ) {
				$(this).find('.cd-timeline-img, .cd-timeline-content').removeClass('is-hidden').addClass('bounce-in');
			}
		});
	});

	// 直播 滚动后固定位置fixed
	$.each($("#posfix"),function(){
		var $pos = $(this);
		var $left = $pos.offset().left;
		var $top = $pos.offset().top;
		var initTop = 0;
		$(window).on('scroll',function(){
			var scrollTop = $(document).scrollTop();
			if(scrollTop > initTop){
				if($pos.offset().top <= $(window).scrollTop()+$(".wrap-header").height()+20){
					$pos.css({
						"position": "fixed",
						"left": $left + "px",
						"top": "80px"
					});
				}
				// console.log("down");
				initTop = scrollTop;
			}
			if(scrollTop < initTop){
				$top = $pos.offset().top;
				if($(window).scrollTop() <= $(".wrap-header").height()+$(".ces-hgruop").height()){
					$pos.css({
						"position": "relative",
						"left": "0px",
						"top": "0px"
					});
					// console.log("up");
				}
				initTop = scrollTop;
			}
		});
		$pos.find("span").each(function(index,elem){
			$(elem).on("click",function(){
				var val = $(this).find("input[type=radio]").val();
				var spanTop = $("span[data-date="+val+"].qDate").eq(0).parents(".cd-timeline-block").offset().top
				$("html,body").animate({
	                scrollTop: spanTop - 80 + "px"
	            },500);
				// return false;
			});
		})
	});
});